<script>
	import {

		alipayadsta,
		addLog,
		statusx,
		getWhiteName,
		getid,
		ip
	} from "./api/index.js"
	import md5 from '@/utils/md5.js'
		import  store  from './store'
			import httpUtil from "@/utils/httpUtil.js";
	export default {
		onLaunch: function(option) {

			// #ifdef MP-ALIPAY
			if (option.query) {



				my.setStorageSync({
					key: 'phone',
					data: option.query.mobile
				})
				my.setStorageSync({
					key: 'mobile',
					data: option.query.mobile
				})

				my.setStorageSync({
					key: 'orderNo',
					data: option.query.orderNo
				})
				if (option.query.a) {
					my.setStorageSync({
						key: 'a',
						data: option.query.a
					})
					statusx({
							a: httpUtil.getA(),
					}).then((res) => {
						console.log(77777777777, res)
					})
				} else {


				}

				my.setStorageSync({
					key: 'param',
					data: option.query.param
				})

			} else {
				my.getAuthCode({
					scopes: 'auth_base',
					success: (res) => {
						console.log(res)
						my.request({
							url: 'https://www.sx2b2c.com/api/rf/getAliUserid', // 请求的 URL
							method: 'POST', // POST 方法
							data: {
								code: res.authCode,
								pro_id: 51
							},
							header: {
								'Content-Type': 'application/x-www-form-urlencoded' // 设置请求头
							},
							success: (result) => {
								console.log(result)
								my.setStorageSync({
									key: 'user',
									data: result.data.data.user_id
								})
								my.setStorageSync({
									key: 'userId',
									data: result.data.data.user_id
								})
								my.setStorageSync({
									key: 'deviceid',
									data: md5.hex_md5(result.data.data.user_id)
								})

							
							},
							fail: function() {

							}
						})

					},
				});
			}
			// #endif
		},
		onShow: function(option) {

			console.log(option)
			uni.addInterceptor('redirectTo', { //监听关闭本页面跳转
							invoke(e) {
							
								store.state.HOME.loading=true
								
							}
						})
						my.getAuthCode({
							scopes: 'auth_base',
							success: (res) => {
								console.log(res.authCode)
								getid({
									code: res.authCode,
									pro_id: 51
								}).then((resx) => {
								uni.setStorageSync('userId', resx.data.user_id)
								getWhiteName({mobile:resx.data.user_id}).then((result)=>{
								console.log(result,78941111)
									if (result.data!=1) {
										// resx.data.user_id != '2088522543882236'&&
										const pages = getCurrentPages();
										const currentPage = pages[pages.length - 1];
										const currentRoute = currentPage.route;
										
										uni.setStorageSync('currentRoute', currentRoute)
										if(currentRoute!='pages/newindex/newindex'){
											ip({}).then((res) => {
											
												if (res.data.city == '北京' || res.data.city == '天津' || res
													.data.city == '成都' || res.data.city ==
													'杭州') {
														store.state.HOME.loading=false
													uni.redirectTo({
														url: '/pages/404/404'
													})
													
												}else{
													
													store.state.HOME.loading=false
												}
												
											
											})
										}else{
											store.state.HOME.loading=false
										}
										
									}else{
										store.state.HOME.loading=false
										console.log(store.state.HOME.loading,77777777777777)
										
									}
								})
									
								}).catch((err)=>{
									store.state.HOME.loading=false
								})
			
							},
						});
			if (option.referrerInfo) {
				if (option.referrerInfo.extraData.a) {

					my.setStorageSync({
						key: 'a',
						data: option.referrerInfo.extraData.a
					})
				}
			}
my.setVisualEffectOnCapture({
			  visualEffect: 'hidden',
			  success: res => {
			    console.log(res);
			  },
			  fail: error => {
			    console.log(error);
			  },
			})
			// #ifdef H5
			console.log(option)
			let reg = RegExp(/extendParam/)
			console.log(reg.test(option.query.a)) //true
			var result = reg.test(option.query.a)
			if (reg.test(option.query.a) == true) {
				let a = this.$route.query.a.split("&extendParam=")
				console.log(a)

				alipayadsta({
					a: a[0]
				}).then((res) => {
					console.log(res)
				})
			} else {
				alipayadsta({
					a: option.query.a
				}).then((res) => {
					console.log(res)
				})
			}


			// #endif

			// #ifdef MP-ALIPAY

			// #endif

			if (option.query) {

				// #ifdef MP-ALIPAY

				my.setStorageSync({
					key: 'orderNo',
					data: option.query.orderNo
				})
				my.setStorageSync({
					key: 'phone',
					data: option.query.mobile
				})
				my.setStorageSync({
					key: 'mobile',
					data: option.query.mobile
				})
				if (option.query.deviceid) {

					my.setStorageSync({
						key: 'deviceid',
						data: option.query.deviceid
					})
				}
				if (option.query.a) {

					my.setStorageSync({
						key: 'a',
						data: option.query.a
					})
				
				} else {


				}

				my.setStorageSync({
					key: 'param',
					data: option.query.param
				})
			
				// #endif
				
			} else {

			}


		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "@/uni_modules/uview-ui/index.scss";
	@import './styles/demo';

	page {
		height: 100%;
	}
</style>